<html>
<head><meta charset="utf-8"><title>Removing `mir_const_qualif` query · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html">Removing `mir_const_qualif` query</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="179130347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179130347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179130347">(Oct 26 2019 at 15:33)</a>:</h4>
<p>The <code>mir_const_qualif</code> query computes the value of <code>NeedsDrop</code>, <code>HasMutInterior</code> etc. on the final value of a <code>const</code> so we know whether e.g. <code>&amp;CONST</code> is promotable. However it also returns a second value, a bitset of promotable locals, that is not used anywhere except promotion.</p>
<p>I want to make the qualifs in the final value an output of <code>mir_validated</code> instead and remove <code>mir_const_qualif</code>. This will make the code that does promotion more regular across <code>const</code>, <code>static</code>, <code>const fn</code>, etc. and will save a bit of space in the query cache. It will also help me fix a bug with <code>[expr; 2]</code> promotion in <code>const</code>s (<a href="https://github.com/rust-lang/rust/issues/65732" target="_blank" title="https://github.com/rust-lang/rust/issues/65732">#65732</a>), since the logic for promotion in a <code>const</code> will have full access to the list of promotion <code>Candidate</code>s instead of just a bitset of  promotable locals with no context.</p>
<p>Does anyone foresee a problem with this? This is my first time modifying queries. The only difference in evaluation order is that <code>mir_validated</code> will be called on a <code>const</code> if  a reference to it is encountered in another MIR body. I don't think this can result in a query cycle where one did not exist before, and we should be doing the same amount of work minus a few arena allocations.</p>



<a name="179144490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179144490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179144490">(Oct 26 2019 at 22:40)</a>:</h4>
<p><code>as_local_hir_id</code> is returning <code>None</code> for <code>MaybeUninitialized::UNINIT</code> on the following query stack. Is there something I need to make sure gets executed first?</p>
<div class="codehilite"><pre><span></span>query stack during panic:
#0 [mir_built] processing `core::mem::MaybeUninit::&lt;T&gt;::UNINIT`
#1 [unsafety_check_result] processing `core::mem::MaybeUninit::&lt;T&gt;::UNINIT`
#2 [mir_const] processing `core::mem::MaybeUninit::&lt;T&gt;::UNINIT`
#3 [mir_validated] processing `core::mem::MaybeUninit::&lt;T&gt;::UNINIT`
#4 [mir_validated] processing `collections::btree::node::LeafNode::&lt;K, V&gt;::new`
#5 [mir_borrowck] processing `collections::btree::node::LeafNode::&lt;K, V&gt;::new`
#6 [analysis] running analysis passes on this crate
</pre></div>



<a name="179144541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179144541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179144541">(Oct 26 2019 at 22:42)</a>:</h4>
<p>Ah, I guess it's because one is in a different crate from the other.</p>



<a name="179145140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179145140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179145140">(Oct 26 2019 at 23:01)</a>:</h4>
<p>So what I really want is for one function to generate the results for two queries, specifically <code>mir_validated</code> and <code>mir_const_qualif</code>. The result of <code>mir_validated</code> is a <code>Steal</code>, which is not <code>Rustc{En,De}codable</code>, but I need to cache the result of <code>mir_const_qualif</code> on disk I think? This means I can't combine the two?</p>



<a name="179149967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179149967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179149967">(Oct 27 2019 at 01:53)</a>:</h4>
<p>After re-reading the rustc guide, I think this is an external vs local provider issue?</p>



<a name="179163514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179163514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179163514">(Oct 27 2019 at 09:36)</a>:</h4>
<p>You could have <code>mir_const_qualif</code> get the qualifs from <code>mir_validated</code> and then you would only have to encode that.</p>



<a name="179179053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179179053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179179053">(Oct 27 2019 at 17:21)</a>:</h4>
<p>Ah, yes, I'll give this a try. Thank you!</p>



<a name="179427554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179427554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179427554">(Oct 30 2019 at 12:50)</a>:</h4>
<p>that's... one way, I guess? in general, I wish we had first-class support for "one provider, multiple queries" (cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span>)</p>



<a name="179527992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179527992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179527992">(Oct 31 2019 at 12:54)</a>:</h4>
<p>Yes -- we had some thoughts about this related to how we handle MIR lowering as well  that might actually be relevant</p>



<a name="179527994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179527994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179527994">(Oct 31 2019 at 12:54)</a>:</h4>
<p>I should try to write them down</p>



<a name="179557005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Removing%20%60mir_const_qualif%60%20query/near/179557005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Removing.20.60mir_const_qualif.60.20query.html#179557005">(Oct 31 2019 at 17:47)</a>:</h4>
<p>BTW, removing <code>mir_const_qualif</code> was an attempt to fix some bugs around promotion for array initializers in consts while keeping the existing const-checking/promotion pass. Once the combined pass is removed, two separate queries will once again be the best strategy.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>